package windbell.domain.risk.impl;

import edu.fudan.langlab.domain.document.IDocumentContainer;
import edu.fudan.langlab.domain.document.impl.DocumentStorageImpl;
import edu.fudan.mylang.pf.IObjectFactory;
import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import windbell.domain.risk.RiskCheckItem;
import windbell.domain.risk.RiskCheckItemQrCode;
import windbell.domain.risk.impl.RiskCheckItemImpl;
import windbell.domain.risk.proxy.RiskCheckItemQrCodeProxy;

@Entity
@DiscriminatorValue("RISKCHECKITEMQRCODE_TYPE")
public class RiskCheckItemQrCodeImpl extends DocumentStorageImpl implements RiskCheckItemQrCode {
  public RiskCheckItemQrCodeImpl() {
    super();
  }
  
  public RiskCheckItemQrCodeImpl(final RiskCheckItem riskCheckItem) {
    super();
    this.riskCheckItem = riskCheckItem;
  }
  
  @JoinColumn(name = "riskCheckItem_id")
  @ManyToOne(targetEntity = RiskCheckItemImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private RiskCheckItem riskCheckItem;
  
  public RiskCheckItem getRiskCheckItem() {
    return this.riskCheckItem;
  }
  
  public IDocumentContainer getContainer() {
    return this.riskCheckItem;
  }
  
  public static RiskCheckItemQrCode create(final RiskCheckItem riskCheckItem, final IObjectFactory objectFactory) {
    windbell.domain.risk.RiskCheckItemQrCode riskCheckItemQrCode = new windbell.domain.risk.impl.RiskCheckItemQrCodeImpl(
    	riskCheckItem
    );
    objectFactory.create(riskCheckItemQrCode);
    return riskCheckItemQrCode;			
    
  }
  
  public static RiskCheckItemQrCode createRiskCheckItemQrCodeImpl(final RiskCheckItem riskCheckItem, final IObjectFactory objectFactory, final Procedure1<RiskCheckItemQrCode> init) {
    windbell.domain.risk.RiskCheckItemQrCode riskCheckItemQrCode = new windbell.domain.risk.impl.RiskCheckItemQrCodeImpl(
    	riskCheckItem
    );
    objectFactory.create(riskCheckItemQrCode);
    init.apply(riskCheckItemQrCode);
    return riskCheckItemQrCode;			
    
  }
  
  public RiskCheckItemQrCodeProxy toProxy() {
    windbell.domain.risk.proxy.RiskCheckItemQrCodeProxy proxy = new windbell.domain.risk.proxy.RiskCheckItemQrCodeProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
